import request from '@/utils/request'
import axios from 'axios'
import store from "@/store";

// 任务列表
export function getPlatformList(params) {
  return request({
    url: '/platform/list',
    method: 'get',
    params,
  })
}
// 凭证是否过期
export function getPlatformIsExpires(params) {
  return request({
    url: '/platform/isExpires',
    method: 'get',
    params,
  })
}
// 获取验证码
export function getPlatformCaptchaImage(params) {
  return request({
    url: '/platform/getCaptchaImage',
    method: 'get',
    params,
    config: {
      timeout: 20000
    }
  })
}
// 数据上传保存
export function savePlatform(data) {
  return request({
    url: '/platform/save',
    method: 'post',
    data,
    config: {
      timeout: 60000
    }
  })
}
// 根据剂计量计任务id，下载报送卡
export function downloadSubmissionCard(params) {
  // return request({
  //   url: '/platform/downloadSubmissionCard',
  //   method: 'get',
  //   params,
  //   headers: {
  //     responseType: 'blob',
  //   }
  // })
  return new Promise((resolve, reject) => {
    axios({
      url: process.env.VUE_APP_BASE_API + `/platform/downloadSubmissionCard`,
      timeout: 0,
      method: 'get',
      params,
      responseType: 'blob',
      headers: {
        "Authorization": 'Bearer ' + store.getters.token
      },
    }).then(res => {
      resolve(res)
    }).catch(() => {
      resolve(false);
    });
  });
}
// 数据上传提交
export function submitPlatform(data) {
  return request({
    url: '/platform/submitted',
    method: 'post',
    data,
    config: {
      timeout: 60000
    }
  })
}

// 修改密码
export function updatePwd(params) {
  return request({
    url: '/platform/updatePwd',
    method: 'post',
    params,
  })
}

// 参与人员------------------------------------

// 列表
export function participantList(params) {
  return request({
    url: '/platform/participant/list',
    method: 'get',
    params,
  })
}
// 添加
export function addParticipant(data) {
  return request({
    url: '/platform/participant/addParticipant',
    method: 'post',
    data,
  })
}
// 删除
export function removeParticipant(taskPlatformParticipantIds) {
  return request({
    url: `/platform/participant/removeParticipant/${taskPlatformParticipantIds}`,
    method: 'get',
  })
}
// 参与人员END--------------------------------